package com.catazy.mvvmlib.ext.lifecycle

import android.app.Activity
import android.app.Application
import android.os.Bundle
import com.blankj.utilcode.util.LogUtils

/**
 * 作者: Tao
 * 日期: 2024/1/24
 * 时间: 17:47
 * 描述: Activity生命周期管理监听
 * 主要作用: 用于监听Activity的生命周期,并将Activity加入到栈中
 */
class ActivityLifecycleCallbacksImpl: Application.ActivityLifecycleCallbacks {

    override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) {
        LogUtils.i("ActivityLifecycleCallbacksImpl", "-->onActivityCreated")
        /*加入Activity管理栈*/
        ActivityManager.addActivityToStack(activity)
    }

    override fun onActivityStarted(activity: Activity) {
        LogUtils.i("ActivityLifecycleCallbacksImpl", "-->onActivityStarted")
    }

    override fun onActivityResumed(activity: Activity) {
        LogUtils.i("ActivityLifecycleCallbacksImpl", "-->onActivityResumed")
    }

    override fun onActivityPaused(activity: Activity) {
        LogUtils.i("ActivityLifecycleCallbacksImpl", "-->onActivityPaused")
    }

    override fun onActivityStopped(activity: Activity) {
        LogUtils.i("ActivityLifecycleCallbacksImpl", "-->onActivityStopped")
    }

    override fun onActivitySaveInstanceState(activity: Activity, outState: Bundle) {
        LogUtils.i("ActivityLifecycleCallbacksImpl", "-->onActivitySaveInstanceState")
    }

    override fun onActivityDestroyed(activity: Activity) {
        LogUtils.i("ActivityLifecycleCallbacksImpl", "-->onActivityDestroyed")
        ActivityManager.popActivityToStack(activity)
    }
}